/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.skatiger.jrove.el;

import javax.el.ValueExpression;
import javax.el.VariableMapper;

public final class CompositeVariableMapper extends VariableMapper {

    private final VariableMapper var0;

    private final VariableMapper var1;

    public CompositeVariableMapper(VariableMapper var0, VariableMapper var1) {
        this.var0 = var0;
        this.var1 = var1;
    }

    /**
     * @see javax.el.VariableMapper#resolveVariable(java.lang.String)
     */
    @Override
    public ValueExpression resolveVariable(String name) {
        ValueExpression ve = this.var0.resolveVariable(name);
        if (ve == null) {
            return this.var1.resolveVariable(name);
        }
        return ve;
    }

    /**
     * @see javax.el.VariableMapper#setVariable(java.lang.String,
     *      javax.el.ValueExpression)
     */
    @Override
    public ValueExpression setVariable(String name, ValueExpression expression) {
        return this.var0.setVariable(name, expression);
    }

}
